import MySQLdb


########################################################################
class Data_Access (object):
    """
    Cria conexao com a Base de Dados
    """    
    dba = MySQLdb.connect (host = 'localhost', user = 'root', passwd = '', db = 'DB_1CLIC2LEARN') 


    #----------------------------------------------------------------------
    def __init__(self, id_vulnerability, pl_attack):
        """
        Construtor:
        Configura para a vulnerabilidade selecionada
        """      
        self.id_vulnerability = id_vulnerability
        self.pl_attack = pl_attack
        
    #----------------------------------------------------------------------   
    def getAttack (self):
        """
        RESTORNA OS ATAQUES DA VULNERABILIDADE INFORMADA
        """
        self.cursor = self.dba.cursor()
        self.cursor.execute('SELECT ATTACK FROM ' + self.pl_attack)
        self.result = self.cursor.fetchall()
        
        return self.result
        
    #----------------------------------------------------------------------    
    def getMitigation (self):
        """
        RESTORNA A FORMA DE MITIGAR A VULNERABILIDADE INFORMADA
        """
        self.cursor = self.dba.cursor()
        self.cursor.execute('SELECT MITIGATION FROM MITIGATION WHERE ID_VULNERABILITY = ' + str(self.id_vulnerability))
        self.result = self.cursor.fetchone()
        
        return self.result
    
    #----------------------------------------------------------------------
    def getResponse (self):
        """
        RESTORNA AS RESPOSTAS QUE A VULNERABILIDADE INFORMADA APRESENTA
        """
        self.cursor = self.dba.cursor()
        self.cursor.execute('SELECT RESPONSE FROM ATTACK_RESPONSE WHERE ID_VULNERABILITY = ' + str(self.id_vulnerability))
        self.result = self.cursor.fetchall()
        
        return self.result
        